package com.jimmy.ioc.annotation;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;

/**
 * @version 1.0
 * @ ClassName BookController
 * <p> TODO
 * @ author JIMMY
 * @ Date 2020/10/23 0023 下午 9:39
 */
@Controller
public class BookController {
    public static void main(String[] args) {
        test();
    }
    public static void test(){
        //1读取配置文件
//        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-book.xml");
//        BookService bookService = (BookService) ctx.getBean("bookService");
//        bookService.save();
//        BookService bookService1 = (BookService) ctx.getBean("bookService");
//        bookService1.save();

        // spring3.0  @configuration @bean配合 来生成BEAN 相当于实例工厂生成BEAN
//        BookService bookService2 = (BookService) ctx.getBean("a");
//        bookService2.save();
//        BookService bookService3 = (BookService) ctx.getBean("a");
//        bookService3.save();
        // spring3.0  @configuration @bean配合 来生成BEAN 相当于实例工厂生成BEAN
        //注解风格的配置文件直接不用第一句读取配置文件(太麻烦了很少用)
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
        ctx.register(MyBeanFactory.class);
        //刷新
        ctx.refresh();
        BookService bookService = (BookService) ctx.getBean("a");
        bookService.save();
    }
}
